package com.gree.pool.alone;


import java.text.DecimalFormat;
import java.util.List;


import com.gree.pool.ThreadPool;
import com.gree.entity.TrsT021RunmoveRecord;
import com.gree.utils.SpringBeanFactoryUtils;
import com.gree.service.ITrsT021RunmoveRecordService;


/** 所有用户 */
public class ReadFileAlone implements Runnable {
	public final static DecimalFormat    df   = new DecimalFormat("######0");   
	public static void getReadFile() {
		ITrsT021RunmoveRecordService ckps = (ITrsT021RunmoveRecordService) SpringBeanFactoryUtils.getBean("recordService");// 运行记录
		int cim = ThreadPool.getCorePoolSize();
		List<TrsT021RunmoveRecord> list =null;
		while (true) {
			/*** 获取正在运行的 */
			  list = ckps.getRuningRecord(cim);
			if (list.size() > 0) {
				//System.out.println("\n数据集合长度:"+list.size());
				for (TrsT021RunmoveRecord record : list) {
					String companyId = record.getCompanyId();// 公司代码
					String loginId = record.getLoginId();
					String path = record.getFileUrl();// 文件路径
					String userId = record.getHoldUser();// 操作对象
					String infoId = record.getInfoId();
					String fileName = record.getFileName();
					Integer rowLines=  Integer.parseInt(df.format(record.getRowLines()));
					 
					ThreadPool.testNoThreadTask(path, loginId, userId, infoId, companyId, fileName, rowLines);
					try {
						Thread.sleep(2000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			} else {
				try {
					Thread.sleep(2000);
					continue;
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			while (true) {
				try {
					cim = ThreadPool.getSize();
					//System.out.println("\n线程前数："+cim);
					if (cim == 0) {
						Thread.sleep(1000);
						continue;
					} else {
						//System.out.println("\n线程数："+cim+"\tbareak");
						break;
					}
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}

	@Override
	public void run() {
		getReadFile();
	}

}
